package kingwing.dc.core.echarts;

import java.util.List;
import javax.annotation.Resource;

import kingwing.dc.core.model.EmotionAn;
import kingwing.dc.core.orm.hibernate.CommonHibernateDao;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.bstek.dorado.annotation.Expose;
@Component("echartsPR")
public class EchartsPR {
	@Resource(name=CommonHibernateDao.BEAN_ID)
	private CommonHibernateDao commonHibernateDao;
	@SuppressWarnings("unchecked")
	@Expose
	public String getOptionJsonString(String infoId){
		String str="";
		List<EmotionAn> list =null;
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(EmotionAn.class);
		if(StringUtils.isNotEmpty(infoId)){
			
			detachedCriteria.add(Restrictions.eq("infosId", infoId));
			
			list=(List<EmotionAn>) commonHibernateDao.query(detachedCriteria);
			if(list.size()>0){
				str +="{title:'"+list.get(0).getInfosTitle().trim()+"',data:[";
				for (EmotionAn emotionAn : list) {
					str +="{value:"+Double.valueOf(emotionAn.getFront())+", name:'正面指数'},";
					str +="{value:"+Double.valueOf(emotionAn.getDownside())+", name:'负面指数'}";
				}
				str +="]}";
			}
		}
		return str;
	}
	
}
